﻿(function ($) {
    var init = function () {
        $(".help-popup").each(function () {
            var $this = $(this);

            $this.find(".help-icon").click(function () {
                $this.find(".help-message-container")
                    .css("display", "block")
                    .attr("data-animating", "true")
                    .fadeIn();
            });
        });
    };
    $(document).ready(init).ajaxStop(init);

    $(document).click(function () {
        $(".help-popup .help-message-container").each(function () {
            var $this = $(this);

            if ($this.attr("data-animating") == "true") {
                $this.removeAttr("data-animating");
            } else if ($this.css("display") == "block" && !$this.is(":animated")) {
                $this.fadeOut();
            }
        });
    });
})(jQuery);